<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use app\admin\model\AdminlogModel;

//管理员
class Adminlog extends Controller
{
    public function index()
	{
	    return $this->view->fetch();
	}
	public function datas(){
		$page['page']=input('page');
		$where=[];
		$where_u=[];
		if(input('time')){
			$times=explode(',',input('time'));
			$time_l=strtotime($times[0]);
			$time_s=strtotime($times[1].' 23:59:59');
			$where[]=['createtime','between time',[$time_l,$time_s]];
			// $where[]=['created_at','>',$time_l];
			// $where[]=['created_at','<',$time_s];
		}
		if(input('kay')){
			$where_u['a.adminname']=['like','%'.input('kay').'%'];
		}
		if(input('status')){
			$where['status']=['=',input('status')];
		}
		$where['type_is']='1';
		$data =AdminlogModel::alias('l')->join('admin a','l.a_id=a.id')->where($where)->order('l.id', 'desc')->field('l.*,a.adminname')->where($where_u)->paginate(input('limit'),false,$page);
		$page = $data->render();
		$list = $data->items();
		// dump($list);
		//获取分页显示
		// return $data;
		// $lists['totalRow']  = [
		// 	'price'=>AdminlogModel::where($where)->sum('price').' 元',
		// ];
		$lists['code']=0;
		$lists['msg']='';
		$lists['count']=AdminlogModel::alias('l')->join('admin a','l.a_id=a.id')->where($where)->where($where_u)->count();
		$lists['data']=$list;
		echo json_encode($lists);
	}
	public function dels_list(){
		$where[]=['id','in',input('ids')];
		$AdminlogModel=new AdminlogModel;
		$del=$AdminlogModel->destroy(input('ids'));
		if($del){
			return message('操作成功');
		}
		return message('操作失败',false);
	}
}